﻿using System;
using System.Windows.Input;

namespace PrintConverter
{
    using static Delegates;

    public class Command : ICommand
    {
        private readonly Executer _executer;
        private readonly Checker _checker;

        public Command(
            Executer executer,
            Checker checker = null)
        {
            _executer = executer;
            _checker = checker;
        }

        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            if (_checker != null)
            {
                return _checker(parameter);
            }
            else
            {
                return true;
            }
        }

        public void Execute(object parameter)
        {
            if (_executer != null)
            {
                _executer(parameter);
            }
        }

        public void RaiseCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, EventArgs.Empty);
            }
        }
    }
}
